﻿		<div id="content">
			<div id="adminwidget">
				<div class="tabnav">
					<ul>
						<li><a href="#news">ข่าวสาร</a></li>
						<li><a href="#settings">ตั้งค่าระบบ</a></li>
					</ul>
				</div>
				<div class="tabdiv">
					<div style="text-align:right;margin-bottom:15px;"><a href="javascript:void(0)" class="super small secondary" onclick="$('addnewsdiv').setStyle('display','block');">เพิ่มข่าว</a></div>
					<div id="addnewsdiv" style="display:none;margin-bottom:15px;">
						<fieldset>
							<legend>เพิ่มข่าว</legend>
							<form action="{$APP_URL}/admin" method="post" id="addnewsform">
								<textarea name="news_text" class="input-text validate['required']" cols="100" rows="6"></textarea>
								<button type="submit" class="super secondary small">ตกลง</button>
								<button type="reset" class="super secondary small" onclick="$('addnewsdiv').setStyle('display','none');">ยกเลิก</button>
								<input type="hidden" name="action" value="addnews" />
								<input type="hidden" name="session" value="{$user.session_id}" />
							</form>
						</fieldset>
					</div>				
				{if !empty($news)}
					<table id="news_list" width="670">
						<tr>
							<th width="10%">ไอดี</th>
							<th width="40%">ข้อความ</th>
							<th width="20%">เมื่อ</th>
							<th width="20%">สถานะ</th>
							<th width="10%">ลบ</th>
						</tr>
					{foreach from=$news item=n}
						<tr id="news-tr-{$n.news_id}" class="trnews">
							<td>{$n.news_id}</td>
							<td>{$n.news_text}</td>
							<td>{$n.news_time}</td>
							<td>
								<input type="radio" class="news_showing_toggle" name="news_showing-{$n.news_id}" id="news_showing-{$n.news_id}" value="yes"{if $n.is_show == 1} checked="checked"{/if} /> แสดง 
								<input type="radio" name="news_showing-{$n.news_id}" class="news_showing_toggle" id="news_showing-{$n.news_id}" value="no"{if $n.is_show == 0} checked="checked"{/if} /> ไม่แสดง
							</td>
							<td>
								<a href="{$APP_URL}/admin/?action=deletenews&id={$n.news_id}" onclick="return setConfirm(this, true, {literal}function(){deleteCallback({/literal}{$n.news_id}{literal});}{/literal});">ลบ</a>
							</td>
						</tr>
					{/foreach}
					</table>
				{/if}
				</div>
				<div class="tabdiv">
					<form action="{$APP_URL}/admin" method="post" id="settingsform">
						<table width="670">
							<tr>
								<td><label>ชื่อฟอรั่ม</label></td>
								<td width="50%"><input type="text" name="app_title" class="input-text validate['required']" size="50" value="{$setting.app_title}" /></input></td>
							</tr>
							<tr>
								<td><label>จำนวนกระทู้ต่อหน้า</label>(หน้าแรก)</td>
								<td width="50%"><input type="text" name="alltopic_display" class="input-text validate['required','digit']" size="50" value="{$setting.alltopic_display}" /></input></td>
							</tr>
							<tr>
								<td><label>จำนวนกระทู้เด่น</label>(ด้านข้าง)</td>
								<td width="50%"><input type="text" name="hottopic_display" class="input-text validate['required','digit']" size="50" value="{$setting.hottopic_display}" /></input></td>
							</tr>
							<tr>
								<td><label>จำนวนกระทู้ล่าสุด</label>(ด้านข้าง)</td>
								<td eidth="50%"><input type="text" name="lasttopic_display" class="input-text validate['required','digit']" size="50" value="{$setting.lasttopic_display}" /></td>
							</tr>
							<tr>
								<td><label>หน่วงเวลาแสดงข่าว</label>(วินาที)</td>
								<td width="50%"><input type="text" name="news_fader_duration" class="input-text validate['required','digit']" size="50" value="{$setting.news_fader_duration}" /></td>
							</tr>
							<tr>
								<td colspan="3" align="center" valign="middle"><button type="submit" class="super secondary small">บันทึก</button></td>
							</tr>
						</table>
						<input type="hidden" name="action" value="editsettings" />
						<input type="hidden" name="session" value="{$user.session_id}" />
					</form>
				</div>
			</div>
			<div style="clear: both;">&nbsp;</div>
		</div>
		{literal}
		<script type="text/javascript">
		window.addEvent('domready', function(){	
			new TabSwapper({
				selectedClass: 'selected',
				deselectedClass: '',
				tabs: $$('.tabnav li'),
				clickers: $$('.tabnav li a'),
				sections: $$('div.tabdiv'),
				cookieName: 'admin_tabs',
				smooth: true,
				smoothSize: false
			});
			new FormCheck('addnewsform', {'trimValue': true});
			new FormCheck('settingsform', {'trimValue': true});
			if($$('.news_showing_toggle')){
				$$('.news_showing_toggle').each(function(el){
					el.addEvent('change', function(e){
						var id = el.getProperty('id').split('-')[1];
						var val = el.getProperty('value');
						new Request.JSON({
							url: APP.URL + '/admin',
							onSuccess: function(){
								el.getParent('tr').highlight('#ffff99');
							}
						}).post({id: id, is_show: val, session: APP.TOKEN, action: 'togglenewsshow'});
					});
				});
			}
		});
		function deleteCallback(id){
			var el = $('news-tr-' + id);
			el.fade('out');
			setTimeout(function(){
				el.dispose();
				if($$('#news_list tr').length <= 1){
					$('news_list').dispose();
				}
			}, 800)
		}
		</script>
		<style>
		.tabdiv {padding: 15px !important;}
		#news_list {
			border: 1px #ddd solid;
			border-collapse: collapse;
			border-spacing: 0px;
		}
		#news_list tr th {
			color: #000;
			padding: 5px;
			font-weight: bold;
			background: #eee;
			border-bottom: 1px #ddd solid;
		}
		#news_list tr td {
			padding: 5px;
			text-align: center;
			border-bottom: 1px #ddd dotted;
		}
		</style>
		{/literal}		
		<!-- end #content -->